import { notNilEmpty } from 'qx-util';
import { IPSAppDERS } from '../../app/dataentity/ipsapp-ders';
import { LogUtil } from '../../core';
import { IPSModelObject } from '../../ipsmodel-object';
import { PSModelServiceProxyImpl } from '../../psmodel-service-proxy-impl';

/**
 * 全局默认通用代理
 *
 * @author chitanda
 * @date 2021-06-08 20:06:55
 * @export
 * @class PSAppDERSServiceProxy
 * @extends {PSModelServiceProxyImpl}
 */
export class PSAppDERSServiceProxy extends PSModelServiceProxyImpl {
  getPSModel4(
    relatedPSModelObject: IPSModelObject,
    cls: string,
    objNode: any,
    strTag: string,
  ): IPSModelObject {
    switch (strTag) {
      case 'getParentPSAppDEField':
        return this.getParentPSAppDEField(
          relatedPSModelObject as IPSAppDERS,
          objNode,
        );
    }
    return this.getRealPSModelService().getPSModel4(
      relatedPSModelObject,
      cls,
      objNode,
      strTag,
    );
  }

  getParentPSAppDEField(r: IPSAppDERS, obj: any): any {
    const entity = r.getMinorPSAppDataEntity();
    if (notNilEmpty(entity)) {
      if (entity.isFill) {
        return entity.findPSAppDEField(obj);
      } else {
        LogUtil.warn('实体未填充，无法查找属性!', entity);
      }
    }
    return null;
  }
}
